package com.qf.exc;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 汤奇
 * @version V1.0
 * @Project BookPro
 * @Package com.qf.exc
 * @Description: 自定义异常处理器, 项目中的所有异常都会汇集到这里进行异常处理
 * @Date 2022/6/8 20:06
 */
public class MyExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
       //打印堆栈信息日志
        e.printStackTrace();

        ModelAndView modelAndView = new ModelAndView();
        //给前端页面返回数据信息
        modelAndView.addObject("error","别急,稍等一下!");

        //跳转到指定页面
        modelAndView.setViewName("error2");
        return modelAndView;

    }
}
